package com.ztgf.shopping.api.client.shop;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.bo.shop.ShopAnnualFeePayOnlineBO;
import com.ztgf.shopping.models.bo.shop.ShopAnnualFeeReturnBO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.shopping.models.service.shop.IShopAnnualFeeService;
import com.ztgf.shopping.models.bo.shop.ShopAnnualFeeBO;
import com.ztgf.shopping.models.dto.shop.ShopAnnualFeeDTO;

/**
 * 店铺年费控制器
 *
 * @author zhanghualang
 * @Date 2020-06-16 14:36:53
 */

@RestController
@RequestMapping("/api/shopAnnualFee")
@Slf4j
@Api(value = "ShopAnnualFeeApiController",tags = "店铺年费Api接口")
public class ShopAnnualFeeApiController {
    @DubboReference
    private IShopAnnualFeeService shopAnnualFeeService;

    @ApiOperation(value = "根据店铺ID获取年费信息",notes = "根据店铺ID获取年费信息")
    @PostMapping(value = "/getByShopId")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result getByShopId(@RequestParam("id") Long id) {
        ShopAnnualFeeDTO dto = shopAnnualFeeService.getByShopId(id);
        if (dto != null){
            return new Result<>(dto);
        } else {
            return new Result<>(CodeEnum.FAIL);
        }
    }

    @ApiOperation(value = "余额缴纳年费",notes = "余额缴纳年费")
    @PostMapping(value = "/updatePaidByBalance")
    public Result updatePaidByBalance(Long id, String mobile, String captcha) {
        return shopAnnualFeeService.updatePaidByBalance(id, mobile, captcha);
    }

    @ApiOperation(value = "网银缴纳年费",notes = "网银缴纳年费")
    @PostMapping(value = "/updatePaidByOnline")
    public Result updatePaidByOnline(ShopAnnualFeePayOnlineBO bo) {
        return shopAnnualFeeService.updatePaidByOnline(bo);
    }

    @ApiOperation(value = "年费缴纳回调接口",notes = "年费缴纳回调接口")
    @PostMapping(value = "/updatePaidReturn")
    public Result updatePaidReturn(ShopAnnualFeeReturnBO bo) {
        return shopAnnualFeeService.updatePaidReturn(bo);
    }

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<ShopAnnualFeeDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        ShopAnnualFeeDTO dto = shopAnnualFeeService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "店铺年费列表",notes = "店铺年费列表")
    @PostMapping("/queryPageList")
    public Result<Page<ShopAnnualFeeDTO>> queryPageList(ShopAnnualFeeBO bo){
        Wrapper<ShopAnnualFeeDTO> wrapper = new EntityWrapper<>();
        if (bo.getStatus() != null){
            wrapper.eq("status", bo.getStatus());
        }
        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<ShopAnnualFeeDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = shopAnnualFeeService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
